Async Web API

Similar to MVC application, when you create the controller class in Web API you need to inherited controller with “ApiController” abstract class. Where “ApiController” class implements the “IHttpCpntroller” and “IDispose” interface. By in design all the Web API controllers are asynchronous. IHttpController define the method “ExecuteAsync” to be implemented by ApiController, this force the Web API to act as asynchronous.

       
public abstract class ApiController : IHttpController, IDisposable
    {
public virtual Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken);

  
    

Web API uses the “HttpRequestMessage” and “HttpResponseMessage” class for its communication and it is available in “System.Net.Http” namespace